<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class FavoritesController extends Controller
{
    //
    public function index(Request $request)
    {
    	$goods = DB::table("collect")->join("goods","goods.id","=","collect.gid")->get();
    	$list=DB::table('type')->get();
        $config=DB::table('config')->get();
    	return view("home.favorites",["list"=>$list,"config"=>$config,"goods"=>$goods]);
    }
    public function destroy($id)
    {

    	$row =DB::table("collect")->where("gid",$id)->delete();
    	if($row>0){
    		return redirect("home1/favorites");
    	}
    }
    public function store($id)
    {
        $data['gid']=$id;
        $data['uid']=session()->get('homeuser')->id;
        $data['time']=time();
        $row=DB::table('collect')->insertGetId($data);
        if ($row>0) {
            return back()->with('msg','已加入收藏');
        }
    }
}
